package lvbu.wang.lvbuoperator.core;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by DaiQing.Zha on 2016/9/14 0014.
 */
public abstract class BaseFragment extends Fragment {

    private View rootView;
    public BaseActivity fa;

    /**
     * onCreateView杩斿洖鐨勫氨鏄痜ragment瑕佹樉绀虹殑view銆�     *
     * @param inflater
     * @param container
     * @param savedInstanceState
     * @return
     */
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if(rootView==null){
            rootView = getRootView(inflater,container,savedInstanceState);
            builderView(rootView);
        }else{
            ViewGroup p = (ViewGroup) rootView.getParent();
            if (p != null) {
                p.removeAllViewsInLayout();
            }
        }
        return rootView;
    }


    /**
     * 查找view
     */
    protected <T extends View> T findView(int id) {
        return (T) rootView.findViewById(id);
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        fa = (BaseActivity) activity;
    }

    public abstract View getRootView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState);

    public abstract void builderView(View rootView);
}
